package com.javacoo.swing.jxbrowser.content;

import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.WindowConstants;

import com.javacoo.swing.jxbrowser.BaseBrowser;
import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.LoadURLParams;
import com.teamdev.jxbrowser.chromium.swing.BrowserView;

/**
 * 使用POST加载URL
 * <li></li>
 * 要通过URL加载网页并发送一些POST数据，请使用Browser.loadURL（LoadURLParams params）方法。以下代码演示了如何使用额外header加载URL并以不同格式发送POST数据：
 * application/x-www-form-urlencoded
 *
 * browser.loadURL(new LoadURLParams("https://gitee.com/javacoo", "myKey=myValue&myKey2=myValue2"));
 *
 * text/plain
 *
 * browser.loadURL(new LoadURLParams("https://gitee.com/javacoo", "Some Text...", "Content-Type: text/plain\n"));
 *
 * application/json
 *
 * browser.loadURL(new LoadURLParams("https://gitee.com/javacoo", "{\"title\":\"Hello\"}", "Content-Type: application/json\n"));
 * @author: duanyong@jccfc.com
 * @since: 2020/9/25 9:17
 */
public class LoadingUrlWithPost extends BaseBrowser {
    public static void main(String[] args) {
        Browser browser = new Browser();
        BrowserView browserView = new BrowserView(browser);

        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.add(browserView, BorderLayout.CENTER);
        frame.setSize(700, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        //application/x-www-form-urlencoded
        browser.loadURL(new LoadURLParams(BASE_URL, "myKey=myValue&myKey2=myValue2"));
        //text/plain
        browser.loadURL(new LoadURLParams(BASE_URL, "Some Text...", "Content-Type: text/plain\n"));
        //application/json
        browser.loadURL(new LoadURLParams(BASE_URL, "{\"title\":\"Hello\"}", "Content-Type: application/json\n"));
    }
}
